package com.stormrage.edu.dao.exam.impl;

import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import com.stormrage.edu.dao.exam.ExmStudentExamDao;
import com.stormrage.entity.exam.ExmStudentExam;
import com.stormrage.entity.exam.rep.ExmStudentExamRep;
import com.stormragetech.core.dao.MysBaseDao;
import com.stormragetech.core.exception.StormrageTechException;

/**
 * @Title: ExmStudentExamDaoImpl.java
 * @Package com.stormrage.edu.dao.exam.impl
 * @Description: 学员考试试题 Dao
 * @author www.stormragetech.com
 * @date 2016年5月17日
 * @version V1.0
 */
@Repository
public class ExmStudentExamDaoImpl extends MysBaseDao implements ExmStudentExamDao {

	private static final Logger logger = LoggerFactory.getLogger(ExmStudentExamDaoImpl.class);

	@Override
	public Integer create(final ExmStudentExam arg0) throws StormrageTechException {

		logger.debug(" 【 Dao 】-【 ExmStudentExamDao 】-【 create 】-【 STARTED 】");

		final String query = "INSERT INTO exm_student_exam (stu_id, type, question) VALUES (:stuId, :type, :question)";
		logger.debug(" 数据库执行语句为 " + query);

		Integer index = create(query, arg0);

		logger.debug(" 【 Dao 】-【 ExmStudentExamDao 】-【 create 】-【 COMPLETED 】");
		return index;

	}

	@Override
	public void delete(final Map<String, Object> map) throws StormrageTechException {

		logger.debug(" 【 Dao 】-【 ExmStudentExamDao 】-【 queryRepListByStuId 】-【 STARTED 】");

		final String query = "DELETE FROM exm_student_exam WHERE stu_id = :stuId";
		logger.debug(" 数据库执行语句为 " + query);

		update(query, map);

		logger.debug(" 【 Dao 】-【 ExmStudentExamDao 】-【 queryRepListByStuId 】-【 COMPLETED 】");

	}

	@Override
	public List<ExmStudentExamRep> queryRepListByStuId(final Map<String, Object> map) throws StormrageTechException {

		logger.debug(" 【 Dao 】-【 ExmStudentExamDao 】-【 queryRepListByStuId 】-【 STARTED 】");

		final String query = "SELECT * FROM exm_student_exam WHERE stu_id = :stuId";
		logger.debug(" 数据库执行语句为 " + query);

		List<ExmStudentExamRep> array = queryList(query, ExmStudentExamRep.class, map);

		logger.debug(" 【 Dao 】-【 ExmStudentExamDao 】-【 queryRepListByStuId 】-【 COMPLETED 】");
		return array;

	}

}
